const express = require('express');
const path = require('path')
const app = express()

// 导入router对象
const userRouter = require('./routes/userRouter')

app.use(express.static(path.join(__dirname, './static')));
app.use(express.urlencoded({ extended: true }))
app.use(express.json())
app.all('*', (req, res, next) => {
    res.header("Access-Control-Allow-Origin", "*");
    res.header(
        "Access-Control-Allow-Headers",
        "Authorization,X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method"
    );
    res.header(
        "Access-Control-Allow-Methods",
        "GET, POST, OPTIONS, PATCH, PUT, DELETE"
    );
    res.header("Allow", "GET, POST, PATCH, OPTIONS, PUT, DELETE");
    next();
})

// 使用路由对象
app.use(userRouter);

app.use('*', (req, res) => {
    res.send({ message: '暂无请求', status: 404 })
})
app.listen(3000, () => {
    console.log('3000端口服务已启用!!')
})